const jwt = require('jsonwebtoken')
const baseConfig={
    secretKey:"woods2213127617",////密钥里边的字符可以自定义
    unlessList:[                // 不校验token的路由
        '/api/admin/loginin',
         /^\/uploads\// 
    ],

     getToken(tokenStr){
        var res;
        try {
            if (tokenStr !== undefined) {

                var token=tokenStr.replace("Bearer ",'')
                 console.log(token)
                let result = jwt.verify(token, baseConfig.secretKey) || {};
                res = result.token || {};
            }
        } catch (e) {
            res = e;
        }     
        return res;
    },
    setToken(token){
        var tokenStr = jwt.sign({ token }, baseConfig.secretKey, { expiresIn: 60 * 60 * 20 * 30 })
        return tokenStr
    },
     
}

module.exports = baseConfig